import Hls from './hls'
/**
 * ts切片播放
 * @param videoSrc 视频地址
 * @param video video的dom
 */
Hls.hlsPlay = function(videoSrc,video){
  if(!videoSrc||!video){
    return;
  }
  let hls = null;
  if (video.canPlayType('application/vnd.apple.mpegurl')) {
    video.src = videoSrc;
  }else if (Hls.isSupported()) {
    hls = new Hls();
    hls.loadSource(videoSrc);
    hls.attachMedia(video);
    hls.on(Hls.Events.MANIFEST_PARSED, function() {
      if(video.autoplay){
        video.play();
      }
    });
    hls.on(Hls.Events.ERROR, function (event, data) {
      if(data.details.indexOf("manifest")>=0) {
        video.src = videoSrc;
        hls.destroy();
      }
    });
  }else{
    video.src = videoSrc;
  }
  return hls;
}
export default Hls
